$(function () {
    $.ajax({
        type: "post",
        url: "http://www.rice.com/app/api/h5_access",
        data: {
            method: "level_data"
        },
        dataType: "json",
        success: function (result) {
            if (result.status == "1") {
                var data = result.data.data;
                var sttr = "";
                for (var i in data) {
                    if (data[i].allow_app_pay == 0) {
                        sttr += ' <a style="cursor:pointer;" data-level="' + data[i].level + '" data-name="' + data[i].name + '">';
                        sttr += '<div style="padding:20px 10px 20px 10px;"><div clas="am-u" ><div class="am-u-sm-12" style="padding: 10px;background: #eaeaea;border: 1px solid #DEDEDE;border-radius: 15px;display: flex;align-items: center;justify-content: space-between;">';
                        sttr += ' <div class="am-u-sm-5" style="text-align: center;display: flex;align-items: center;width: 100%;"><i style="display:block;width:40px;height:40px;margin-right: 10px;"><img src="' + data[i].logo_img + '" alt=""  style="width: 40px;height:40px;"/></i><p style="font-size: 16px;color:#333;margin:0;">' + data[i].name + '</p></div>';
                        sttr += '<div class="am-u-sm-7" ><div style="font-size: 15px;color:#333">' + data[i].note + '</div>';
                    };
                    if (data[i].allow_app_pay == 1) {
                        sttr += ' <a onclick="javascript:tanc(this);" style="cursor:pointer;" data-level="' + data[i].level + '" data-name="' + data[i].name + '">';
                        sttr += '<div style="padding:20px 10px 20px 10px;"><div clas="am-u" ><div class="am-u-sm-12" style="padding: 10px;background: #fff;border-radius: 15px;display: flex;align-items: center;justify-content: space-between;">';
                        sttr += ' <div class="am-u-sm-5" style="text-align: center;display: flex;align-items: center;width: 100%;"><i style="display:block;width:40px;height:40px;margin-right: 10px;"><img src="' + data[i].logo_img + '" alt=""  style="width: 40px;height:40px;"/></i><p style="font-size: 16px;color:#333;margin:0;">' + data[i].name + '</p></div>';
                        sttr += '<div class="am-u-sm-7" ><div style="font-size: 15px;color:#333">' + data[i].note + '</div>';
                    }
                    if (data[i].is_open == "1") {
                        sttr += '<div style="text-align:right;font-size: 15px;color:#333"><a href="get_activity.html">参与活动</a></div></div>';
                    } else {
                        sttr += '<div style="text-align:right;display:none;font-size: 15px;color:#333"><a href="get_activity.html">参与活动</a></div></div>';
                    }


                    sttr += '</div></div></div>';
                    sttr += '</a><div style="clear:both;"></div>';
                }
                $(".up_table").html(sttr);
            } else if (result.status == "2") {
                alert(result.message);
                location.href = "login.html";
            } else {
                alert(result.message);
            }
        }
    })


    var level_name = sessionStorage.getItem("level_name");
    var user_level = sessionStorage.getItem("user_level");
    var token = sessionStorage.getItem("token");
    var method = "get_pay_type";
    $("#level_name").html(level_name);
})

function upClick(obj) {
    var level_name = $(obj).attr("data-name");
    var user_level = $(obj).attr("data-level");
    var token = sessionStorage.getItem("token");
    var che = $(obj).attr("data-chan");
    var d = {};
    d.method = "get_upgrade_url";
    d.token = token;
    d.level = user_level;
    d.level_name = level_name;
    d.type = che;
    $.ajax({
        type: "post",
        url: "http://www.rice.com/app/api/h5_access",
        data: d,
        dataType: "json",
        success: function (result) {

            if (result.status == "1") {
                var data = result.data;
                sessionStorage.setItem("url1", data.url);
                sessionStorage.setItem("money", data.money);
                sessionStorage.setItem("code_num_upgrade", data.code_num_upgrade);
                sessionStorage.setItem("trade_no", data.trade_no);
                sessionStorage.setItem("channel", data.channel);
                if (data.channel == "unionpay") { //银联

                    location.href = data.url;
                } else {

                    location.href = "ewma.html";
                }
            } else if (result.status == "2") {
                alert(result.message);
                location.href = "login.html";
            } else {
                alert(result.message);
            }
        }
    })
}

function tanc(obj) {
    var level_name = $(obj).attr("data-name");
    var user_level = $(obj).attr("data-level");
    $.ajax({
        type: "post",
        url: "http://www.rice.com/app/api/h5_access",
        data: {
            method: "get_pay_type"
        },
        dataType: "json",
        success: function (result) {
            if (result.status == "1") {
                layer.open({
                    type: 1,
                    offset: 'b',
                    content: '<div style="width:200px;height:auto;"><ul id="tan-con" class="am-list h35"></ul></div>',
                    btn: '关闭全部',
                    btnAlign: 'c',
                    shade: 1,
                    yes: function () {
                        layer.closeAll();
                    }
                });

                var data = result.data.data;
                var sttr = "";

                for (var i in data) {
                    sttr += "<li data-chan=" + data[i].channel + " class='h35' style='cursor:pointer;height:35px;line-height:35px;' onclick='javascript:upClick(this);' data-name='" + level_name + "'data-level='" + user_level + "'>";
                    sttr += "<img src='" + data[i].img_url + "' width='30px'/>";
                    sttr += "<sapn style='width:70%;text-align:center;display:inline-block;'>" + data[i].name + "</span>";
                    sttr += "</li>";
                }
                $("#tan-con").html(sttr);

            } else if (result.status == "2") {
                alert(result.message);
                location.href = "login.html";
            } else {
                alert(result.message);
            }
        }
    })

}